import axios from 'axios';
import { Toast } from 'vant'



const startLoading = () => {
    Toast.loading({
        message: '加载中...',
        forbidClick: true,
    });
}

const endLoading = () => {
    Toast.clear();
}

const badRequest = () => {
    Toast.fail('请求失败');
}

// 请求拦截
axios.interceptors.request.use((config) => {
    // 加载
    startLoading();
    return config;
})


// 响应拦截
axios.interceptors.response.use((response) => {
    // 结束loading
    endLoading();
    return response;
}, error => {
    // 结束loading
    badRequest();
    // 错误提醒
    return Promise.reject(error);
})

export default axios;